
/*
 * Sketch_oct31b_ds18b20.hpp
 * PLUGGED map https://blog.51cto.com/u_15672212/5581449
 * 定义DS18B20数据引脚
 * PLUGGED GPIO14 = D5
 */
#ifndef SKETCH_OCT31B_DS18B20_H
#define SKETCH_OCT31B_DS18B20_H
#include <DallasTemperature.h>
#include <OneWire.h>
#include "Arduino.h"
#define Ds18B20SensorPin 14  //Nano接A6 ESP8266接A0 ESP32接A5或者其他ADC引脚
/****************************************DS18B20 part****************************************/
class Sketch_oct31b_ds18b20 {
private:
  int ONE_WIRE_BUS_PIN = Ds18B20SensorPin;
  int TEMPERATURE_PRECISION = 9;
  int ds18b20TimeInterval = 3 * 1000;
  unsigned long cal_delayStart = 0;  // the time ds18b20 delay started
  /*
      * 功能描述：输出数据
      * Main function, get and show the temperature
      */
  float printData(DeviceAddress deviceAddress);

  /**
      * 功能描述：读取设备物理地址
      * 功能描述：function to print a device address
      */
  void printAddress(DeviceAddress deviceAddress);

  /**
      * 功能描述：读取设备检测温度
      * 功能描述：function to print the temperature for a device
      */
  float printTemperature(DeviceAddress deviceAddress);
public:
  DallasTemperature sensors;
  OneWire oneWire;
  DeviceAddress insideThermometer, outsideThermometer;
  String str_insideTemp;
  String str_outsideTemp;
  // ----- Constructor -----
  Sketch_oct31b_ds18b20();
  Sketch_oct31b_ds18b20(int one_wire_bus_pin);
  ~Sketch_oct31b_ds18b20();

  int getPin();

  /**
      * 功能描述：初始化DS18B20温度探测棒
      */
  void initDS18b60DevManager();

  void initDev();

  /**
      * 功能描述：读取设备数据接口
      */
  void loadDS18B20API(long _interval);

  float getDs18b20Temp();
};
#endif